package com.dongdong.android.widget;

import android.Manifest;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.Uri;
import android.net.wifi.SupplicantState;
import android.net.wifi.WifiManager;
import android.os.Build;
import android.provider.Settings;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.dongdong.android.keyboard.NumKeyBoardView;
import com.dongdong.android.widget.ui.safe.AesDemoActivity;
import com.dongdong.android.widget.utils.permission.PermissionsManager;
import com.dongdong.android.widget.utils.permission.PermissionsResultAction;
import com.dongdong.android.wifibox.WifiBoxActivity;


public class MainActivity extends AppCompatActivity {

    private NumKeyBoardView numkey;

    private TextView tvWifiSetting;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        numkey = (NumKeyBoardView) findViewById(R.id.ket_board);
        tvWifiSetting = (TextView) findViewById(R.id.tvWifiSetting);
        findViewById(R.id.btnToAes).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MainActivity.this, AesDemoActivity.class);
                startActivity(intent);
            }
        });
        tvWifiSetting.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                    String[] permissions = {Manifest.permission.ACCESS_FINE_LOCATION};
                    PermissionsManager.getInstance().requestPermissionsIfNecessaryForResult
                            (MainActivity.this,
                                    permissions, new PermissionsResultAction() {
                                        @Override
                                        public void onGranted() {
                                            toWifiSetActivity();
                                        }

                                        @Override
                                        public void onDenied(String permission) {

                                        }
                                    });
                } else {
                    toWifiSetActivity();
                }

            }
        });
        numkey.setOnKeyBoardClickListener(new NumKeyBoardView.OnKeyBoardClickListener() {
            @Override
            public void onOutPut(String num) {
                Toast.makeText(MainActivity.this, num, Toast.LENGTH_LONG).show();
            }

            @Override
            public void onDetele() {
                Toast.makeText(MainActivity.this, "删除", Toast.LENGTH_LONG).show();
            }

            @Override
            public void onNextClick() {
                Toast.makeText(MainActivity.this, "完成", Toast.LENGTH_LONG).show();
            }
        });

    }


    private void toWifiSetActivity() {
        Intent intent = new Intent(MainActivity.this, WifiBoxActivity.class);
        startActivity(intent);
    }


}
